#pragma once

class CXmlLite
{
public:
	CXmlLite(LPCTSTR Xml) : m_Xml(Xml)
	{
	}

public:
	static CString XmlToJson(LPCTSTR Xml);

public:
	int GetResult()
	{
		return _tstoi(Get(_T("ResultCode")));
	}
	CString GetMessage()
	{
		return Get(_T("ErrorMsg"));
	}
	CString Get(LPCTSTR Name)
	{
		CString result;

		CString tag;
		tag.Format(_T("<%s"), Name);
		LPCTSTR b = _tcsstr(m_Xml, tag);
		if (b != NULL)
		{
			LPCTSTR p = _tcsstr(b, _T(">"));
			if (p != NULL)
			{
				b = p + 1;
			}
		}
		tag.Format(_T("</%s>"), Name);
		if (b != NULL)
		{
			LPCTSTR p = _tcsstr(b, tag);
			if (p != NULL)
			{
				result = CString(b, p - b);
			}
		}

		return result;
	}

public:
	operator LPCTSTR()
	{
		return m_Xml;
	}

private:
	CString m_Xml;
};
